<?php

/**
 * This class Mac_give access to helpers functions
 *
 * @author Mathieu Pheulpin - sokaru91@gmail.com
 */

class Mac_Db_Helper {
    
    public static function prepareValue ($value)
    {
        if (is_numeric($value)) {
            return mysql_real_escape_string($value);
        } else {
            return "'".mysql_real_escape_string($value)."'";
        }
    }
    
    public static function outputOrderBy ($order) {
        $return = "";
        if (is_array($order)) {
            foreach ($order as $field => $dir) {
                $return .= $field.' '.$dir.' ';
            }
        } else {
            $return .= (string)$order;
        }
        return trim($return);
    }
    
    public static function outputWhere (array $where) {
        if (!empty($where)) {
            if (sizeof($where) > 1) {
                array_walk($where, function(&$value) {
                    $value = '('.$value.')';
                });
            }
        }
        return implode(' OR ', $where);
    }
}